



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class QuestionsDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public QuestionsDB()
        {
        }

        public QuestionsDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<Questions> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<Questions> lstRet = new List<Questions>();

            string strQuery = " select " + strTop  + " * from dbo.[Questions]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Questions obj = new Questions();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["CoursesID"] != DBNull.Value)
                    {
                        obj.CoursesID = (System.Int64)dr["CoursesID"];
                    }
                    else
                    {
                        obj.CoursesID = -1;
                    } 
 if (dr["QuestionTypesID"] != DBNull.Value)
                    {
                        obj.QuestionTypesID = (System.Int64)dr["QuestionTypesID"];
                    }
                    else
                    {
                        obj.QuestionTypesID = -1;
                    } 
 if (dr["QuestionAR"] != DBNull.Value)
                    {
                        obj.QuestionAR = (System.String)dr["QuestionAR"];
                    }
                    else
                    {
                        obj.QuestionAR = "";
                    } 
 if (dr["QuestionEN"] != DBNull.Value)
                    {
                        obj.QuestionEN = (System.String)dr["QuestionEN"];
                    }
                    else
                    {
                        obj.QuestionEN = "";
                    } 
 if (dr["QuestionDegree"] != DBNull.Value)
                    {
                        obj.QuestionDegree = (System.Double)dr["QuestionDegree"];
                    }
                    else
                    {
                        obj.QuestionDegree = -1;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<Questions> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Questions> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , Questions obj)
        {
            
            

                    DbParameter prmCoursesID = con.createParameter();
                    prmCoursesID.ParameterName = "@CoursesID";
                    prmCoursesID.DbType =DbType.Int64;
                    if (obj.CoursesID == null)
                    {
                        prmCoursesID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCoursesID.Value = obj.CoursesID;
                    }
                

                    


                    DbParameter prmQuestionTypesID = con.createParameter();
                    prmQuestionTypesID.ParameterName = "@QuestionTypesID";
                    prmQuestionTypesID.DbType =DbType.Int64;
                    if (obj.QuestionTypesID == null)
                    {
                        prmQuestionTypesID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionTypesID.Value = obj.QuestionTypesID;
                    }
                

                    


                    DbParameter prmQuestionAR = con.createParameter();
                    prmQuestionAR.ParameterName = "@QuestionAR";
                    prmQuestionAR.DbType =DbType.String;
                    if (obj.QuestionAR == null)
                    {
                        prmQuestionAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionAR.Value = obj.QuestionAR;
                    }
                

                    


                    DbParameter prmQuestionEN = con.createParameter();
                    prmQuestionEN.ParameterName = "@QuestionEN";
                    prmQuestionEN.DbType =DbType.String;
                    if (obj.QuestionEN == null)
                    {
                        prmQuestionEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionEN.Value = obj.QuestionEN;
                    }
                

                    


                    DbParameter prmQuestionDegree = con.createParameter();
                    prmQuestionDegree.ParameterName = "@QuestionDegree";
                    prmQuestionDegree.DbType =DbType.Double;
                    if (obj.QuestionDegree == null)
                    {
                        prmQuestionDegree.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionDegree.Value = obj.QuestionDegree;
                    }
                

                    


           



            string strQuery = " insert into dbo.[Questions] ([CoursesID],[QuestionTypesID],[QuestionAR],[QuestionEN],[QuestionDegree]) VALUES (@CoursesID,@QuestionTypesID,@QuestionAR,@QuestionEN,@QuestionDegree) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmCoursesID,prmQuestionTypesID,prmQuestionAR,prmQuestionEN,prmQuestionDegree);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(Questions obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, Questions obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmCoursesID = con.createParameter();
                    prmCoursesID.ParameterName = "@CoursesID";
                    prmCoursesID.DbType =DbType.Int64;
                    if (obj.CoursesID == null)
                    {
                        prmCoursesID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCoursesID.Value = obj.CoursesID;
                    }
                

                    


                    DbParameter prmQuestionTypesID = con.createParameter();
                    prmQuestionTypesID.ParameterName = "@QuestionTypesID";
                    prmQuestionTypesID.DbType =DbType.Int64;
                    if (obj.QuestionTypesID == null)
                    {
                        prmQuestionTypesID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionTypesID.Value = obj.QuestionTypesID;
                    }
                

                    


                    DbParameter prmQuestionAR = con.createParameter();
                    prmQuestionAR.ParameterName = "@QuestionAR";
                    prmQuestionAR.DbType =DbType.String;
                    if (obj.QuestionAR == null)
                    {
                        prmQuestionAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionAR.Value = obj.QuestionAR;
                    }
                

                    


                    DbParameter prmQuestionEN = con.createParameter();
                    prmQuestionEN.ParameterName = "@QuestionEN";
                    prmQuestionEN.DbType =DbType.String;
                    if (obj.QuestionEN == null)
                    {
                        prmQuestionEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionEN.Value = obj.QuestionEN;
                    }
                

                    


                    DbParameter prmQuestionDegree = con.createParameter();
                    prmQuestionDegree.ParameterName = "@QuestionDegree";
                    prmQuestionDegree.DbType =DbType.Double;
                    if (obj.QuestionDegree == null)
                    {
                        prmQuestionDegree.Value = DBNull.Value;
                    }
                    else
                    {
                        prmQuestionDegree.Value = obj.QuestionDegree;
                    }
                

                    


           



            string strQuery = " update dbo.[Questions] set [CoursesID]=@CoursesID,[QuestionTypesID]=@QuestionTypesID,[QuestionAR]=@QuestionAR,[QuestionEN]=@QuestionEN,[QuestionDegree]=@QuestionDegree where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmCoursesID,prmQuestionTypesID,prmQuestionAR,prmQuestionEN,prmQuestionDegree);

            

        }


        public void Update(Questions obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, Questions obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[Questions]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( Questions obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<Questions> getQuestionsByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<Questions> lstRet = new List<Questions>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<Questions> getQuestionsByID(System.Int64 ID)
                    {
                        List<Questions> lstRet = new List<Questions>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Questions> getQuestionsByCoursesID(ClassDataHandler con,System.Int64 CoursesID)
                    {
                        List<Questions> lstRet = new List<Questions>();


                        DbParameter prmCoursesID = con.createParameter();
                        prmCoursesID.ParameterName = "@CoursesID";
                        prmCoursesID.DbType = DbType.Int64;
                        if (CoursesID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmCoursesID.Value = CoursesID;
                        }


                        lstRet = Select(con, "" , " where [CoursesID]=@CoursesID ", prmCoursesID);



                        return lstRet;

                    }


                    public List<Questions> getQuestionsByCoursesID(System.Int64 CoursesID)
                    {
                        List<Questions> lstRet = new List<Questions>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsByCoursesID(con, CoursesID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Questions> getQuestionsByQuestionTypesID(ClassDataHandler con,System.Int64 QuestionTypesID)
                    {
                        List<Questions> lstRet = new List<Questions>();


                        DbParameter prmQuestionTypesID = con.createParameter();
                        prmQuestionTypesID.ParameterName = "@QuestionTypesID";
                        prmQuestionTypesID.DbType = DbType.Int64;
                        if (QuestionTypesID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmQuestionTypesID.Value = QuestionTypesID;
                        }


                        lstRet = Select(con, "" , " where [QuestionTypesID]=@QuestionTypesID ", prmQuestionTypesID);



                        return lstRet;

                    }


                    public List<Questions> getQuestionsByQuestionTypesID(System.Int64 QuestionTypesID)
                    {
                        List<Questions> lstRet = new List<Questions>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsByQuestionTypesID(con, QuestionTypesID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Questions> getQuestionsByQuestionAR(ClassDataHandler con,System.String QuestionAR)
                    {
                        List<Questions> lstRet = new List<Questions>();


                        DbParameter prmQuestionAR = con.createParameter();
                        prmQuestionAR.ParameterName = "@QuestionAR";
                        prmQuestionAR.DbType = DbType.String;
                        if (QuestionAR == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmQuestionAR.Value = QuestionAR;
                        }


                        lstRet = Select(con, "" , " where [QuestionAR]=@QuestionAR ", prmQuestionAR);



                        return lstRet;

                    }


                    public List<Questions> getQuestionsByQuestionAR(System.String QuestionAR)
                    {
                        List<Questions> lstRet = new List<Questions>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsByQuestionAR(con, QuestionAR);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Questions> getQuestionsByQuestionEN(ClassDataHandler con,System.String QuestionEN)
                    {
                        List<Questions> lstRet = new List<Questions>();


                        DbParameter prmQuestionEN = con.createParameter();
                        prmQuestionEN.ParameterName = "@QuestionEN";
                        prmQuestionEN.DbType = DbType.String;
                        if (QuestionEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmQuestionEN.Value = QuestionEN;
                        }


                        lstRet = Select(con, "" , " where [QuestionEN]=@QuestionEN ", prmQuestionEN);



                        return lstRet;

                    }


                    public List<Questions> getQuestionsByQuestionEN(System.String QuestionEN)
                    {
                        List<Questions> lstRet = new List<Questions>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsByQuestionEN(con, QuestionEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Questions> getQuestionsByQuestionDegree(ClassDataHandler con,System.Double QuestionDegree)
                    {
                        List<Questions> lstRet = new List<Questions>();


                        DbParameter prmQuestionDegree = con.createParameter();
                        prmQuestionDegree.ParameterName = "@QuestionDegree";
                        prmQuestionDegree.DbType = DbType.Double;
                        if (QuestionDegree == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmQuestionDegree.Value = QuestionDegree;
                        }


                        lstRet = Select(con, "" , " where [QuestionDegree]=@QuestionDegree ", prmQuestionDegree);



                        return lstRet;

                    }


                    public List<Questions> getQuestionsByQuestionDegree(System.Double QuestionDegree)
                    {
                        List<Questions> lstRet = new List<Questions>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getQuestionsByQuestionDegree(con, QuestionDegree);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<Questions> Search(ClassDataHandler con, Questions obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.CoursesID != -1)
                    {
                        DbParameter prmCoursesID = con.createParameter();
                        prmCoursesID.ParameterName = "@CoursesID";
                        prmCoursesID.DbType =DbType.Int64;
                        if (obj.CoursesID == null)
                        {
                            prmCoursesID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCoursesID.Value = obj.CoursesID;
                        }
                        strWhere += " [CoursesID]=@CoursesID AND ";
                        lstParameters.Add(prmCoursesID);
                     }



                    

                    if (obj.QuestionTypesID != -1)
                    {
                        DbParameter prmQuestionTypesID = con.createParameter();
                        prmQuestionTypesID.ParameterName = "@QuestionTypesID";
                        prmQuestionTypesID.DbType =DbType.Int64;
                        if (obj.QuestionTypesID == null)
                        {
                            prmQuestionTypesID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionTypesID.Value = obj.QuestionTypesID;
                        }
                        strWhere += " [QuestionTypesID]=@QuestionTypesID AND ";
                        lstParameters.Add(prmQuestionTypesID);
                     }



                    

                    if (obj.QuestionAR != "")
                    {
                        DbParameter prmQuestionAR = con.createParameter();
                        prmQuestionAR.ParameterName = "@QuestionAR";
                        prmQuestionAR.DbType =DbType.String;
                        if (obj.QuestionAR == null)
                        {
                            prmQuestionAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionAR.Value = obj.QuestionAR;
                        }
                        strWhere += " [QuestionAR]=@QuestionAR AND ";
                        lstParameters.Add(prmQuestionAR);
                     }



                    

                    if (obj.QuestionEN != "")
                    {
                        DbParameter prmQuestionEN = con.createParameter();
                        prmQuestionEN.ParameterName = "@QuestionEN";
                        prmQuestionEN.DbType =DbType.String;
                        if (obj.QuestionEN == null)
                        {
                            prmQuestionEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionEN.Value = obj.QuestionEN;
                        }
                        strWhere += " [QuestionEN]=@QuestionEN AND ";
                        lstParameters.Add(prmQuestionEN);
                     }



                    

                    if (obj.QuestionDegree != -1)
                    {
                        DbParameter prmQuestionDegree = con.createParameter();
                        prmQuestionDegree.ParameterName = "@QuestionDegree";
                        prmQuestionDegree.DbType =DbType.Double;
                        if (obj.QuestionDegree == null)
                        {
                            prmQuestionDegree.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionDegree.Value = obj.QuestionDegree;
                        }
                        strWhere += " [QuestionDegree]=@QuestionDegree AND ";
                        lstParameters.Add(prmQuestionDegree);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<Questions> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Questions> Search(Questions obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Questions> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<Questions> SearchOrLike(ClassDataHandler con, Questions obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.CoursesID != -1)
                    {
                        DbParameter prmCoursesID = con.createParameter();
                        prmCoursesID.ParameterName = "@CoursesID";
                        prmCoursesID.DbType =DbType.Int64;
                        if (obj.CoursesID == null)
                        {
                            prmCoursesID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCoursesID.Value = obj.CoursesID;
                        }
                        strWhere += " [CoursesID]=@CoursesID OR ";
                        lstParameters.Add(prmCoursesID);
                     }



                    

                    if (obj.QuestionTypesID != -1)
                    {
                        DbParameter prmQuestionTypesID = con.createParameter();
                        prmQuestionTypesID.ParameterName = "@QuestionTypesID";
                        prmQuestionTypesID.DbType =DbType.Int64;
                        if (obj.QuestionTypesID == null)
                        {
                            prmQuestionTypesID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionTypesID.Value = obj.QuestionTypesID;
                        }
                        strWhere += " [QuestionTypesID]=@QuestionTypesID OR ";
                        lstParameters.Add(prmQuestionTypesID);
                     }



                    

                    if (obj.QuestionAR != "")
                    {
                        DbParameter prmQuestionAR = con.createParameter();
                        prmQuestionAR.ParameterName = "@QuestionAR";
                        prmQuestionAR.DbType =DbType.String;
                        if (obj.QuestionAR == null)
                        {
                            prmQuestionAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionAR.Value = obj.QuestionAR;
                        }
                        strWhere += " [QuestionAR] LIKE @QuestionAR OR ";
                        lstParameters.Add(prmQuestionAR);
                     }



                    

                    if (obj.QuestionEN != "")
                    {
                        DbParameter prmQuestionEN = con.createParameter();
                        prmQuestionEN.ParameterName = "@QuestionEN";
                        prmQuestionEN.DbType =DbType.String;
                        if (obj.QuestionEN == null)
                        {
                            prmQuestionEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionEN.Value = obj.QuestionEN;
                        }
                        strWhere += " [QuestionEN] LIKE @QuestionEN OR ";
                        lstParameters.Add(prmQuestionEN);
                     }



                    

                    if (obj.QuestionDegree != -1)
                    {
                        DbParameter prmQuestionDegree = con.createParameter();
                        prmQuestionDegree.ParameterName = "@QuestionDegree";
                        prmQuestionDegree.DbType =DbType.Double;
                        if (obj.QuestionDegree == null)
                        {
                            prmQuestionDegree.Value = DBNull.Value;
                        }
                        else
                        {
                            prmQuestionDegree.Value = obj.QuestionDegree;
                        }
                        strWhere += " [QuestionDegree]=@QuestionDegree OR ";
                        lstParameters.Add(prmQuestionDegree);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<Questions> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Questions> SearchOrLike(Questions obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Questions> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            